package com.hf.lookatme.zview.activitys;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hf.lookatme.R;
import com.hf.lookatme.commons.CommonMethod;
import com.hf.lookatme.zbean.GuessYourLikeData;
import com.hf.lookatme.zpresenter.Present_Activity_GuessYourLike;
import com.hf.lookatme.zview.adapters.Adapter_RecyclerView_GuessYourLike;
import com.hf.lookatme.zview.adapters.Divider_RecyclerView;
import com.hf.lookatme.zview.interfaces.IView_Activity_GuessYourLike;
import com.orhanobut.logger.Logger;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * 描述：
 * 创建人：JoeShiguang
 * 创建日期：2015/6/24
 * 修改人：
 * 修改日期：
 *
 * @Version 1.0
 */
public class Activity_GuessYourLike extends Activity_Base implements IView_Activity_GuessYourLike {

  private static String TAG = "Activity_GuessYourLike";

  @InjectView(R.id.imageView_actionBar_back)
  ImageView imageButton_actionBar_back;

  @InjectView(R.id.textView_actionBar_title)
  TextView textView_actionBar_title;

  @InjectView(R.id.relativeLayout_guessYourLike_noData)
  RelativeLayout layout_noData;

  @InjectView(R.id.relativeLayout_guessYourLike_haveData)
  RelativeLayout layout_haveData;

  @InjectView(R.id.recyclerView_guessYourLike_context)
  RecyclerView recyclerView_guessData;

  private Present_Activity_GuessYourLike present;

  private Adapter_RecyclerView_GuessYourLike adapter;

  private boolean clickable = false;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_guessyourlike);
    ButterKnife.inject(this);
    try {
      initActionBarAndControls();
      present = new Present_Activity_GuessYourLike(this);
      present.getGuessDataAndInitGuessListView(this);
    } catch (Exception ex) {
      Logger.e(ex.toString());
    }
  }

  private void initActionBarAndControls() {

    imageButton_actionBar_back.setVisibility(View.VISIBLE);
    textView_actionBar_title.setText(getResources().getString(R.string.guessYourLike));

    recyclerView_guessData.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    recyclerView_guessData.addItemDecoration(new Divider_RecyclerView(this, Divider_RecyclerView.VERTICAL_LIST));
  }

  @OnClick(R.id.imageView_actionBar_back)
  void onImageView_actionBar_backClicked(View view) {
    if (!clickable) {
      return;
    }
    if (CommonMethod.isFastDoubleClick()) {
      return;
    }
    Activity_GuessYourLike.this.finish();
  }

  @Override
  public void initGuessList(List<GuessYourLikeData> list_guess) {
    adapter = new Adapter_RecyclerView_GuessYourLike(this, list_guess);
    recyclerView_guessData.setAdapter(adapter);
    adapter.setOnItemClickListener(new Adapter_RecyclerView_GuessYourLike.onItemClickListener() {
      @Override
      public void onItemClick(View view, int position) {
        Toast.makeText(Activity_GuessYourLike.this, position+" clicked", Toast.LENGTH_LONG).show();
      }
    });
    layout_noData.setVisibility(View.GONE);
    layout_haveData.setVisibility(View.VISIBLE);
  }
}